<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :inline="true" :model="queryParams" label-width="68px" size="small">
      <el-form-item label="反馈部门" prop="feedDept">
        <el-input
          v-model="queryParams.feedDept"
          clearable
          placeholder="请输入反馈部门"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="提出者" prop="feedStaff">
        <el-input
          v-model="queryParams.feedStaff"
          clearable
          placeholder="请输入提出者"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="反馈状态" prop="feedStatus">
        <el-select v-model="queryParams.feedStatus" clearable placeholder="请选择反馈状态">
          <el-option
            v-for="dict in dict.type.sys_feed_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="反馈时间" prop="feedTime">
        <el-date-picker v-model="queryParams.feedTime"
                        clearable
                        placeholder="请选择反馈时间"
                        type="date"
                        value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" size="mini" type="primary" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!--    <el-row :gutter="10" class="mb8">-->
    <!--      <el-col :span="1.5">-->
    <!--        <el-button-->
    <!--          type="primary"-->
    <!--          plain-->
    <!--          icon="el-icon-plus"-->
    <!--          size="mini"-->
    <!--          @click="handleAdd"-->
    <!--          v-hasPermi="['system:feed:add']"-->
    <!--        >新增</el-button>-->
    <!--      </el-col>-->
    <!--      <el-col :span="1.5">-->
    <!--            <el-button-->
    <!--              type="success"-->
    <!--              plain-->
    <!--              icon="el-icon-edit"-->
    <!--              size="mini"-->
    <!--              :disabled="single"-->
    <!--              @click="handleUpdate"-->
    <!--              v-hasPermi="['system:feed:edit']"-->
    <!--            >修改</el-button>-->
    <!--      </el-col>-->
    <!--      <el-col :span="1.5">-->
    <!--        <el-button-->
    <!--          type="danger"-->
    <!--          plain-->
    <!--          icon="el-icon-delete"-->
    <!--          size="mini"-->
    <!--          :disabled="multiple"-->
    <!--          @click="handleDelete"-->
    <!--          v-hasPermi="['system:feed:remove']"-->
    <!--        >删除</el-button>-->
    <!--      </el-col>-->
    <!--      <el-col :span="1.5">-->
    <!--        <el-button-->
    <!--          type="warning"-->
    <!--          plain-->
    <!--          icon="el-icon-download"-->
    <!--          size="mini"-->
    <!--          @click="handleExport"-->
    <!--          v-hasPermi="['system:feed:export']"-->
    <!--        >导出</el-button>-->
    <!--      </el-col>-->
    <!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
    <!--    </el-row>-->

    <el-table v-loading="loading" :data="feedList" @selection-change="handleSelectionChange">
      <el-table-column align="center" type="selection" width="55"/>
      <!--      <el-table-column label="反馈id" align="center" prop="feedId" />-->
      <el-table-column align="center" label="反馈部门" prop="feedDept"/>
      <el-table-column align="center" label="反馈内容" prop="feedContent"
                       style="overflow: hidden;text-overflow: ellipsis"
      >

      </el-table-column>
      <el-table-column align="center" label="反馈图片" prop="feedImg" width="100">
        <template slot-scope="scope">
<!--          {{scope.row.feedImg}}-->
          <image-preview :height="50" :src="scope.row.feedImg" :width="50"/>
        </template>
      </el-table-column>
      <el-table-column align="center" label="提出者" prop="feedStaff"/>
      <el-table-column align="center" label="反馈状态" prop="feedStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_feed_status" :value="scope.row.feedStatus"/>
        </template>
      </el-table-column>

      <el-table-column align="center" label="反馈时间" prop="feedTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.feedTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['system:feed:edit']"
            icon="el-icon-edit"
            size="mini"
            type="text"
            @click="handleUpdate1(scope.row)"
          >修改状态
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:feed:edit']"
          >详情
          </el-button>
          <!--          <el-button-->
          <!--            size="mini"-->
          <!--            type="text"-->
          <!--            icon="el-icon-delete"-->
          <!--            @click="handleDelete(scope.row)"-->
          <!--            v-hasPermi="['system:feed:remove']"-->
          <!--          >删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改意见反馈对话框 -->
    <el-dialog :title="title" :visible.sync="open" append-to-body width="500px">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="反馈部门" prop="feedDept">
          <el-input v-model="form.feedDept" placeholder="请输入反馈部门" readonly/>
        </el-form-item>
        <el-form-item label="反馈内容">
          <editor v-model="form.feedContent" :min-height="192" read-only/>
        </el-form-item>
        <el-form-item label="反馈图片" prop="feedImg">
          <image-upload v-model="form.feedImg"/>
        </el-form-item>
        <el-form-item label="提出者" prop="feedStaff">
          <el-input v-model="form.feedStaff" placeholder="请输入提出者" readonly/>
        </el-form-item>
        <el-form-item label="反馈状态" prop="feedStatus">
          <el-radio-group v-model="form.feedStatus">
            <el-radio
              v-for="dict in dict.type.sys_feed_status"
              :key="dict.value"
              :label="parseInt(dict.value)"
              disabled="true"
            >{{ dict.label }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="反馈时间" prop="feedTime">
          <el-date-picker v-model="form.feedTime"
                          clearable
                          placeholder="请选择反馈时间"
                          readonly
                          type="date"
                          value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="title" :visible.sync="open1" append-to-body width="500px">
      <el-form ref="form1" :model="form" label-width="80px">
        <el-form-item label="反馈状态" prop="feedStatus">
          <el-radio-group v-model="form.feedStatus">
            <el-radio
              v-for="dict in dict.type.sys_feed_status"
              :key="dict.value"
              :label="parseInt(dict.value)"
            >{{ dict.label }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <!--        <el-button type="primary" @click="submitForm">确 定</el-button>-->
        <!--        <el-button @click="cancel">取 消</el-button>-->
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {addFeed, delFeed, getFeed, listFeed, updateFeed} from '@/api/system/feed'

export default {
  name: 'Feed',
  dicts: ['sys_feed_status'],
  data() {
    return {
      read: true,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 意见反馈表格数据
      feedList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      open1: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        feedDept: null,
        feedContent: null,
        feedImg: null,
        feedStaff: null,
        feedStatus: null,
        feedTime: null
      },
      // 表单参数
      form: {},
      form1: {},
      // 表单校验
      rules: {
        feedDept: [
          { required: true, message: '反馈部门不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询意见反馈列表 */
    getList() {
      this.loading = true
      listFeed(this.queryParams).then(response => {
        this.feedList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        feedId: null,
        feedDept: null,
        feedContent: null,
        feedImg: null,
        feedStaff: null,
        feedStatus: null,
        feedTime: null
      }
      this.resetForm('form')
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.feedId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '添加意见反馈'
    },
    /** 修改按钮操作 */
    handleUpdate1(row) {
      this.reset()
      const feedId = row.feedId || this.ids
      getFeed(feedId).then(response => {
        this.form = response.data
        this.open1 = true
        this.title = '修改状态'
      })
    },
    handleUpdate(row) {
      this.reset()
      const feedId = row.feedId || this.ids
      getFeed(feedId).then(response => {
        this.form = response.data
        this.open = true
        this.title = '反馈详情'
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form1'].validate(valid => {
        if (valid) {
          if (this.form.feedId != null) {
            updateFeed(this.form).then(response => {
              this.$modal.msgSuccess('修改成功')
              this.open1 = false
              this.getList()
            })
          } else {
            addFeed(this.form).then(response => {
              this.$modal.msgSuccess('新增成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const feedIds = row.feedId || this.ids
      this.$modal.confirm('是否确认删除意见反馈编号为"' + feedIds + '"的数据项？').then(function() {
        return delFeed(feedIds)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('删除成功')
      }).catch(() => {
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/feed/export', {
        ...this.queryParams
      }, `feed_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>

<style lang="scss">
.el-table .cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>
